/**
 * Created with IntelliJ IDEA.
 * User: aleksandr
 * Date: 28.06.13
 */
package com.google.code.bankagregator.core;

import com.google.code.bankagregator.entities.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class BankList {

    private int activeCountD = 0;
    private int activeCountC = 0;

    /**
     * Get active credit counter
     *
     * @return
     */
    public int getActiveCountD() {
        return activeCountD;
    }

    /**
     * Get active deposit counter
     *
     * @return
     */
    public int getActiveCountC() {
        return activeCountC;
    }

    /**
     * Predefined list of banks.
     *
     * @return
     */
    public List<Bank> getBankList() {
        List<Bank> list = new ArrayList<>();
        list.add(new Bank("AlphaBank", "http://www.alfabank.com.ua/"));
        list.add(new Bank("ForumBank", "http://www.forum.ua/forumua/ua/mainnavigation/home/home.html"));
        list.add(new Bank("ImexBank", "http://imexbank.com.ua/rus/main.phtml"));
        list.add(new Bank("АО \"БРОКБИЗНЕСБАНК\"", "http://www.bankbb.com.ua/"));
        list.add(new Bank("Сбербанк России", "http://sberbank.ua/"));
        return list;
    }

    /**
     * Credit list generation
     *
     * @return
     */
    public List<Credit> getCreditList() {
        final Integer[] termSet = {31, 180, 367};
        final Integer[] amountSet = {0, 1000, 10000};
        final Double[] rateSet = {1.0, 5.0, 25.0};
        final Double[] prepaymentSet = {0.0, 10.0, 30.0};

        List<Credit> list = new ArrayList<>();
        int count = 0;
        int localId = 1;
        for (Integer minAmount : amountSet) {
            for (Integer maxAmount : amountSet) {
                if (minAmount < maxAmount) {
                    for (Bank bank : getBankList()) {
                        for (Integer term : termSet) {
                            for (Currency currency : Currency.values()) {
                                for (CreditType creditType : CreditType.values()) {
                                    for (State state : State.values()) {
                                        for (Double rate : rateSet) {
                                            for (Double prepayment : prepaymentSet) {
                                                if (state == State.ACTIVE || state == State.NEW) {
                                                    count++;
                                                }
                                                Credit credit = new Credit();
                                                credit.setId(localId);
                                                credit.setAdded(new Date());
                                                credit.setTerm(term);
                                                credit.setMinAmount(minAmount);
                                                credit.setMaxAmount(maxAmount);
                                                credit.setName("Credit " + creditType.toString() + " N" + localId);
                                                credit.setState(state);
                                                credit.setType(creditType);
                                                credit.setBank(bank);
                                                credit.setCurrency(currency);
                                                credit.setCreditRate(rate);
                                                credit.setPrepayment(prepayment);
                                                list.add(credit);
                                                localId++;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        activeCountC = count;
        return list;
    }

    /**
     * Deposit list generation
     *
     * @return
     */
    public List<Deposit> getDepositList() {
        final Integer[] termSet = {31, 180, 367};
        final Integer[] amountSet = {0, 1000, 10000};
        final Double[] rateSet = {1.0, 5.0, 25.0};
        final Boolean[] refillSet = {true, false};


        List<Deposit> list = new ArrayList<>();
        int count = 0;
        int localId = 1;
        for (Integer minAmount : amountSet) {
            for (Integer maxAmount : amountSet) {
                if (minAmount < maxAmount) {
                    for (Bank bank : getBankList()) {
                        for (Integer term : termSet) {
                            for (Currency currency : Currency.values()) {
                                for (DepositType depositType : DepositType.values()) {
                                    for (State state : State.values()) {
                                        for (Double rate : rateSet) {
                                            for (Boolean refill : refillSet) {
                                                if (state == State.ACTIVE || state == State.NEW) {
                                                    count++;
                                                }
                                                Deposit deposit = new Deposit();
                                                deposit.setId(localId);
                                                deposit.setAdded(new Date());
                                                deposit.setTerm(term);
                                                deposit.setMinAmount(minAmount);
                                                deposit.setMaxAmount(maxAmount);
                                                deposit.setName("Deposit " + depositType.toString() + " N" + localId);
                                                deposit.setState(state);
                                                deposit.setType(depositType);
                                                deposit.setBank(bank);
                                                deposit.setCurrency(currency);
                                                deposit.setDepositRate(rate);
                                                deposit.setRefill(refill);
                                                list.add(deposit);
                                                localId++;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        activeCountD = count;
        return list;
    }
}
